Length of array (C) [migrated]

Posted by physics on Programmers See other posts from Programmers or by physics
Published on 2014-05-30T13:38:05Z Indexed on 2014/05/30 15:58 UTC
Read the original article Hit count: 186

Filed under:
|

I have an array of 10 elements. This array stocks some informations but last information is ended by an symbol "END" (which is -1).

for exemple:

array[0] = 1;
array[1] = 1;
array[2] = 1;
array[3] = 1;
array[4] = 1;
array[5] = 1;
array[6] = END;

So in this case the length is 7 instead of 10.

Here is my algorithm:

for (i = 0; (i < 10) 
             && (array[i] != END); i++)
 {
  ;
 }

at the end i contains the length.

Is it correct or there is an other methode?

© Programmers or respective owner

Related posts about c

    Related posts about array